var GBMessageLayer=cc.Layer.extend({
	
	_messageBoxUp : null,
	_messageBoxDown : null,
	_portraitUp : null,
	_portraitDown : null,
	_textBoxUp : null,
	_textBoxDown : null,
	_gMessageManager : null,
	_messageList : null,
	_size : null,
	
	ctor : function(){
		this._super();
		cc.eventManager.addListener({
			event: cc.EventListener.TOUCH_ONE_BY_ONE,
			swallowTouches: true,
			onTouchBegan: this.onTouchBegan,
			onTouchMoved: this.onTouchMoved,
			onTouchEnded: this.onTouchEnded,
		}, this);
	},
	
	onTouchBegan : function (touch, event) {
		var delta = touch.getDelta(); 
		return true;
	},

	// 拖动事件
	onTouchMoved : function (touch, event) {

	},
	
	// 抬起事件
	onTouchEnded : function (touch, event) {
		if(g_GBMessageLayer.nextMessage()){
			if(_GDWin){
				cc.director.runScene(new cc.TransitionPageTurn(1.2, new ChildMenuScene(),true));
			}	
			else if(_GDFail){
				cc.director.runScene(new cc.TransitionPageTurn(1.2, new ChildMenuScene(),true));
			}
			else
				GLNewGame();
			}
	},
	
	// 下一发消息
	nextMessage : function(){
		_gMessageManager= new MessageManager(this._messageList);
		temp = _gMessageManager.getMessage();
		this.removeAllChildren(true);
		if(temp!=null){
			if(temp.left==true){
				this._messageBoxUp = new cc.Sprite(res.UiModule_png,cc.rect(0, 0, 640, 200));
				this._messageBoxUp.attr({
					anchorX : 0,
					anchorY : 0.5,
					x: 0,
					y: 650
				});
				this.addChild(this._messageBoxUp,900);
				
				this._portraitUp = new cc.Sprite(temp.portrait,cc.rect(temp.x*150, temp.y*150, 150, 150));
				
				this._portraitUp.attr({
					anchorX : 0,
					anchorY : 0.5,
					x: 35,
					y: 660
				});
				this.addChild(this._portraitUp,900);
				
				this._textBoxUp = new cc.LabelTTF(temp.text,"res/font/Microsoft Yahei.ttf", 24);
				this._textBoxUp.setDimensions(cc.size(380, 200));
				this._textBoxUp.attr({
					anchorX : 0,
					anchorY : 1,
					x: 210,
					y: 720,
				color : cc.color(0, 0, 0)
				});
				this.addChild(this._textBoxUp, 1000);
			}
			else{
				this._messageBoxDown = new cc.Sprite(res.UiModule_png,cc.rect(0, 200, 640, 200));
				this._messageBoxDown.attr({
					anchorX : 0,
					anchorY : 0.5,
					x: 0,
					y: 650
				});
				this.addChild(this._messageBoxDown,900);
				
				this._portraitDown = new cc.Sprite(temp.portrait,cc.rect(temp.x*150, temp.y*150, 150, 150));
				this._portraitDown.attr({
					anchorX : 0,
					anchorY : 0.5,
					x: 450,
					y: 660
				});
				this.addChild(this._portraitDown,900);
				this._textBoxDown = new cc.LabelTTF(temp.text, "res/font/Microsoft Yahei.ttf", 24);
				this._textBoxDown.setDimensions(cc.size(380, 200));
				this._textBoxDown.attr({
					anchorX : 0,
					anchorY : 1,
					x: 50,
					y: 720,
					color : cc.color(0, 0, 0)
				});
				this.addChild(this._textBoxDown, 1000);
			}
			return false;
		}
		else
			{
				cc.eventManager.removeListener(this);
				this.removeAllChildren(true);
				this.removeFromParent(true);
				return true;
			}
	},
});